import javax.swing.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileNotFoundException;

/**
 * Created with IntelliJ IDEA.
 * User: Alexandre
 * Date: 13-10-14
 * Time: 15:54
 * To change this template use File | Settings | File Templates.
 */
public class Worker extends SwingWorker<Long, Void> {

    File file;
    PropertyChangeListener p;
    CompteurDeJetons compteur;

    public Worker(File file, PropertyChangeListener p){
        this.file = file;
        this.p = p;
    }

    @Override
    public Long doInBackground(){
        compteur = new CompteurDeJetons();
        long result = 0;
        try {

            result = compteur.Compte(file, p);
        } catch (FileNotFoundException e) {
            System.out.println("Erreur de lecture du fichier: " + e.toString());
        }
        return result;
    }

    @Override
    public void done() {
        System.out.println("Done");
        p.propertyChange(new PropertyChangeEvent(this, "done", false, true));

    }


}
